#ifndef ___RSLIB_LOWLEVEL___
#define ___RSLIB_LOWLEVEL___
 
 
 
//---INCLUDE
//------------------->
#include <RSLib_OLD/Types.hpp>
#include <memory>
 
 
//---NAMESPACES
//-------------->
namespace RSLib{
 
 
 
//---FUNCTION
//	Desc: Commodity version of ZeroObject
//	Note:	needed to cope with <windows.h> include...
//------------------------------------------------------->
#ifndef ZeroMemory
inline void ZeroMemory(PVOID ptr, UINT32 bytes)
{
	memset((void*)ptr,0,(size_t)bytes);
}
#endif
template <typename T> void ZeroObjectMemory(T& object)
{
	ZeroMemory(&object,sizeof(T));
}
inline bool CompareMemory(const void * a,const void * b,UINT32 bytes)
{
	return (memcmp(a,b,bytes) == 0);
}
#ifndef CopyMemory
inline void CopyMemory(void* destination, const void * source,UINT32 bytes)
{
	memcpy(destination,source,bytes);
}
#endif
 
 
namespace LowLevel{
 
 
 
//---MACROS
//	Desc:	macros and a template function (mostly) to get pointers to methods
//	Note:	Does compile on VC7, VC8, GCC4
//----------------------------------------------------------------------------------->
template<typename T> void* AddressToVoidPointer(T address){return *(void**) &address;}
#define OBJECT_ADDRESS(class_,object_)	RSLib::LowLevel::AddressToVoidPointer(&object_)
#define METHOD_ADDRESS(class_,method_)	RSLib::LowLevel::AddressToVoidPointer(&class_::method_)
#define FUNCTION_ADDRESS(function_)		RSLib::LowLevel::AddressToVoidPointer(&function_)
 
 
 
//---MACROS
//	Desc:	dwords/words/bytes extracting macros
//	Note:	from MAKEWORD ... to HIBYTE are extracted from windows headers. others have been added
//---------------------------------------------------------------------------------------------------------------->
#ifndef MAKEWORD
	#define MAKEWORD(a, b)      ((WORD)(((BYTE)((DWORD_PTR)(a) & 0xff)) | ((WORD)((BYTE)((DWORD_PTR)(b) & 0xff))) << 8))
	#define LOWORD(l)           ((WORD)((DWORD_PTR)(l) & 0xffff))
	#define HIWORD(l)           ((WORD)((DWORD_PTR)(l) >> 16))
	#define LOBYTE(w)           ((BYTE)((DWORD_PTR)(w) & 0xff))
	#define HIBYTE(w)           ((BYTE)((DWORD_PTR)(w) >> 8))
#endif 

#define MAKEQWORD(a,b)       ( (((QWORD)a)<<32) | (((QWORD)b)&0xFFFFFFFF) )
#define MAKEDWORD(a, b)      ( (((DWORD)a)<<16) | (((DWORD)b)&0xFFFF) )
#define LODWORD(q)           ( (DWORD) (q & 0xFFFFFFFF) )
#define HIDWORD(q)           ( (DWORD) (q >> 32) )
 
 
 
//---MACROS
//	Desc:	passing of references as optional parameters
//----------------------------------------------------->
#define NULL_REFERENCE(type)				(*((type*)NULL))
#define VALID_REFERENCE(reference)		(&reference != NULL)
#define INVALID_REFERENCE(reference)	(&reference == NULL)
 
 
 
}//namespace LowLevel
}//namespace RSLib
 
 
 
#endif//___RSLIB_LOWLEVEL___